package lambdasinaction.chap6;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class ApptecGrouppingBy {

    public static void main(String... args) {

        ArrayList<String> list = Lists.newArrayList("1", "2", "3", "4", "5");
        AtomicInteger index=new AtomicInteger(0);
        List<List<String>> collect = list.stream().collect(Collectors.groupingBy(p -> index.getAndAdd(1) % 4)).entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList());

        System.out.println(collect);
    }


}
